#include <iostream>
#include <vector>
#include <string>

using namespace std;

class Solution
{
public:
    ListNode *removeNthFromEnd(ListNode *head, int n)
    {
        ListNode dummyHead = new ListNode(0, head);
        if (head == nullptr || head->next == nullptr)
            return nullptr;
        ListNode *p = dummyHead, *q = p;
        while (n-- > 0)
            q = q->next;
        while (q->next != nullptr)
        {
            q = q->next;
            p = p->next;
        }
        // delete &(p->next);
        p->next = p->next->next;
        return dummyHead.next;
    }

private:
    struct ListNode
    {
        int val;
        ListNode *next;
        ListNode() : val(0), next(nullptr) {}
        ListNode(int x) : val(x), next(nullptr) {}
        ListNode(int x, ListNode *next) : val(x), next(next) {}
    };
};

int main()
{
    // TODO
    return 0;
}
